#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int ConvertByteToASC(const unsigned char *Source, int Slen, char *Dest)
{
    //  无效则返回false
    if (Source == NULL || Slen == 0 || Dest == NULL) {
        return 0;
    }
    char tmp[128];
    int index = 0;
    int single = 0;
    for (int i = 0; i < Slen; ++i) {
        sprintf(tmp, "%x%x", Source[i] >> 4, Source[i] & 0xF);
        single = strlen(tmp);
        // printf("single:%d\n", single);
        // printf("tmp:%s\n", tmp);
        strncat(Dest + index, tmp, single);
        index += single;
    }
    // printf("Dest:%s\n", Dest);
    return 1;
}
int ConvertASCToByte(const char *Source, int Slen, unsigned char *Dest)
{
    // 无效则返回false
    if (Slen == 0 || Source == NULL || Dest == NULL) {
        return 0;
    }

    unsigned char tmp;
    char CArr[2] = {'0', '\0'};
    int num = 0;
    int index = 0;

    for (int i = 0; i < Slen; ++i) {
        CArr[0] = Source[i++];
        sscanf(CArr, "%x", &num);
        tmp = num << 4;
        // 若i等于Slen结束循环
        if (i == Slen) {
            tmp |= 0x0F;
            Dest[index++] = tmp;
            break;
        }
        CArr[0] = Source[i];
        sscanf(CArr, "%x", &num);
        tmp |= num;
        Dest[index++] = tmp;
    }
    return 1;
}
int main()
{
    char s[] = "0123456789ABCDEF";
    unsigned char byLen[1];
    char sTemp[20];
    byLen[0] = (unsigned char)(strlen(s) / 2);
    // printf("%d\n", byLen[0]);
    ConvertByteToASC(byLen, 1, sTemp);
    printf("%s\n", sTemp);
    strcat(sTemp + 2, s);
    printf("%s\n", sTemp);
}